/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author simrana
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class GUI extends JFrame {
    

    private JButton incrementC, decrementC, exitC;
    private JTextField currentC;
    private int count;
    private IncrementButtonHandler iCHandler;
    private ExitButtonHandler eCHandler;
    private DecrementButtonHandler dCHandler;
    private JLabel countL;
    
    public GUI() {
        count = 0;
        setTitle("Counter");
        
        Container pane = getContentPane();
        pane.setLayout(new GridLayout (3,2));
        
       
        
        countL = new JLabel("The count is currently");
        incrementC = new JButton("Increment");
        iCHandler = new IncrementButtonHandler();
        incrementC.addActionListener(iCHandler);
        
        decrementC = new JButton("Decrement");
        dCHandler = new DecrementButtonHandler();
        decrementC.addActionListener(dCHandler);
        
        exitC = new JButton("Exit");
        eCHandler = new ExitButtonHandler();
        exitC.addActionListener(eCHandler);
        
        currentC = new JTextField(10);
        currentC.setText("" + count); 
        
        pane.add(countL);
        pane.add(currentC);
        pane.add(incrementC);
        pane.add(decrementC);
        pane.add(exitC);
        pane.add(exitC);
        
        
        setSize(300, 200);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    
    
    
    private class IncrementButtonHandler implements ActionListener {
        
        public void actionPerformed(ActionEvent e) {
            count++;
            currentC.setText("" + count);
        }
    }
    
    private class DecrementButtonHandler implements ActionListener {
      
        public void actionPerformed(ActionEvent e) {
            count--;
            currentC.setText("" + count);
        }
    }
    public class ExitButtonHandler implements ActionListener {
        
   
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    }
}
